<?php

/*
 * curl=>get获取内容
 */
function curl_get_contents($url,$timeout=30) {
    $curlHandle = curl_init();
    curl_setopt( $curlHandle , CURLOPT_URL, $url );
    curl_setopt( $curlHandle , CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt( $curlHandle , CURLOPT_TIMEOUT, $timeout );
    curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, FALSE);   //屏蔽ssl证书和host
    curl_setopt($curlHandle, CURLOPT_SSL_VERIFYHOST, FALSE);
    $result = curl_exec( $curlHandle );
    curl_close( $curlHandle );
    return $result;
}


/**
 * @param $nickname
 * @return mixed|string
 * 过滤emoji表情
 */
function removeEmoji($nickname) {

    $clean_text = "";

    // Match Emoticons
    $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
    $clean_text = preg_replace($regexEmoticons, '', $nickname);

    // Match Miscellaneous Symbols and Pictographs
    $regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';
    $clean_text = preg_replace($regexSymbols, '', $clean_text);

    // Match Transport And Map Symbols
    $regexTransport = '/[\x{1F680}-\x{1F6FF}]/u';
    $clean_text = preg_replace($regexTransport, '', $clean_text);

    // Match Miscellaneous Symbols
    $regexMisc = '/[\x{2600}-\x{26FF}]/u';
    $clean_text = preg_replace($regexMisc, '', $clean_text);

    // Match Dingbats
    $regexDingbats = '/[\x{2700}-\x{27BF}]/u';
    $clean_text = preg_replace($regexDingbats, '', $clean_text);

    return $clean_text;
}

// 英文字母数组
function letter()
{
    // 修改此处!
    $letter = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
    ];

    return $letter;
}


// 判断时间段
function time_solt($h)
{
    if ($h <= 8) {
        return '早上好';
    } elseif ($h <= 12 && $h > 8) {
        return '上午好';
    } elseif ($h <= 13 && $h > 12) {
        return '中午好';
    } elseif ($h > 13 && $h <= 18) {
        return '下午好';
    } else {
        return '晚上好';
    }
}

// 多层递归
function get_cate($arr, $fid = 0)
{
    $newArr = array();
    foreach ($arr as $v) {
        if ($v["parenTid"] == $fid) {
            $newArr[] = array(
                "id" => $v['id'],
                "title" => $v['title'],
                "son" => get_cate($arr, $v['id']),
            );
        }
    }
    return $newArr;
}




/*
 * 图片上传
 * @param string $img 图片名称
 */
function uploadPc($img = 'picUrl')
{
    $file = request()->file($img);
    if (!empty($file)) {
        // 移动到框架应用根目录/public/uploads/ 目录下
        $upload = $file->move(ROOT_PATH . 'public' . DS . 'uploads');

        // halt($upload);
        if ($upload) {


            //返回图片地址
            return 'uploads/' . date('Ymd') . '/' . $upload->getFilename();
        }
        return $file->getError();
    }
    return request()->param($img);
}

/*
 * 生成总订单号
 */
function createNumber()
{
    //订单号码主体（YYYYMMDDHHIISSNNNNNNNN）
    $order_id_main = date('YmdHis') . rand(10000000, 99999999);
    //订单号码主体长度
    $order_id_len = strlen($order_id_main);
    $order_id_sum = 0;
    for ($i = 0; $i < $order_id_len; $i++) {
        $order_id_sum += (int)(substr($order_id_main, $i, 1));
    }
    //唯一订单号码（YYYYMMDDHHIISSNNNNNNNNCC）
    $order_id = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100, 2, '0', STR_PAD_LEFT);

    return $order_id;
}
/*
* 生成店铺订单号码
*/
function make_order($shop_id)
{
    return date('YmdHis', time())
    . mt_rand(10, 99)
    . sprintf('%010d', time() - 946656000)
    . sprintf('%03d', (float)microtime() * 1000)
    . sprintf('%03d', (int)$shop_id % 1000);

}

/*
 *参加活动的商品的ID
 */
function limit_str()
{
    $limit_str = '';
    $limited = \think\Db::name('limited')->field('goods_id')->select();
    $sales = \think\Db::name('sale')->field('goods_id')->select();
    foreach ($limited as $value) {
        $limit_str.=$value['goods_id'].',';
    }
    foreach ($sales as $value) {
        $limit_str.=$value['goods_id'].',';
    }

    return $limit_str;
}






